const puppeteer = require("puppeteer");
const cheerio = require("cheerio");
var evaluate = async ctx =>{
    let {id} = ctx.request.params;
    // console.log(id);//示例id：123692817
    /* 1.新建一个浏览器的实例 */
    const browser = await puppeteer.launch({
        headless:false,
        defaultViewport:null
    });
    /* 2.新建一个页面 */
    const page = await browser.newPage();
    /* 3.到达某个页面 */
    await page.goto(`https://www.duitang.com/p/atlas/?id=${id}`);
    await page.waitForTimeout(3000)
    //获取数据
    let content = await page.content();
    let $ = cheerio.load(content,{
        decodeEntities:false
    })
    let arr=[];
        var avatar = $(".atlas-detail .author img").attr("src");
        var username = $(".atlas-detail .author .name").html();
        var eval_text = [];
        $(".cmt").each((index,value)=>{
            var psd = $(value).find(".cmt-maincont").html();
            eval_text.push(psd);
        })
        arr.push({avatar,username,eval_text})
    ctx.body = arr;
    
}
module.exports = evaluate;